package com.camps.sdk.decrypt;

import com.camps.sdk.common.Constants;
import com.camps.sdk.entity.BaseData;
import com.camps.sdk.entity.DeviceUpMessage;
import com.camps.sdk.entity.LocationData;
import com.camps.sdk.utils.LocationUtils;

import java.util.List;

/**
 * @Author ldaoliang
 * @Date create in 15:40 2021/9/1
 * @Description
 */
public class AnalyzeFactory implements AnalyticalData {


    @Override
    public DeviceUpMessage parseData(String originalData) {
        // *WT,866248050395985,V4,S25,183013,183014,A,2250.2221,N,11391.6196,E,0.12,51,020621,FFFFDFFF#
        //解密
        String[] split = parseCommand(originalData);
        String imei=split[1];
        String commandNumber=split[4];
        String time=split[5];//设备返回指令时间（时分秒）
        String lat = split[7];
        String lng = split[9];
        String speed = split[11];
        String orientation = split[12];
        String date = split[13];//年月日
        String deviceStatus = split[14];//设备状态
        List<Double> list = LocationUtils.transiformLatAndLng(lng, lat);
        BaseData baseReceiver = new BaseData();
        baseReceiver.setDeviceTime(time);
        baseReceiver.setImei(imei);
        baseReceiver.setDeviceStatus(deviceStatus);
        baseReceiver.setDeviceDate(date);
        baseReceiver.setCommandNumber(commandNumber);
        LocationData locationData = new LocationData();
        locationData.setOrientation(Integer.parseInt(orientation));
        locationData.setSpeed(Double.parseDouble(speed));
        locationData.setLatitude(list.get(1));
        locationData.setLongitude(list.get(0));
        baseReceiver.setLocationData(locationData);
        return structureMessage(Constants.REPLY,Constants.FACTORY_RESET,false,"",baseReceiver);
    }
}
